prost = [2]
n = 10000
for i in range(3, n + 1):
    ksun = 0
    for j in prost:
        if i % j == 0:
            ksun = 1
    if ksun == 0:
        prost.append(i)

a = input()
b = []
if int(a) in prost:
    b.append(a)
b.extend([a[:-1], a[1:], a[:-2], a[2:], a[1:-1], a[0], a[1], a[2], a[3]])
x = []
for i in range(len(b)):
    s = b[i]
    for j in range(len(prost)):
        if int(s) == int(prost[j]):
            x.append(int(s))
if len(x) > 0:
    print(max(x))
else:
    print(0)